package com.sxtbbs.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 对密码进行MD5加密
 * @author lovemanai
 *
 */
public class MD5Encryption {
	
	private static String[] seed = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f".split(",");
	
	public static String MD5Encode(String pwd) {
		if(pwd.equals("") || pwd == null) {
			return "";
		}
		StringBuffer pwdEncryption = new StringBuffer();
		try {
			MessageDigest md = MessageDigest.getInstance("md5");
			byte[] b = md.digest(pwd.getBytes());
			for(int i = 0; i < b.length; i++) {
				int temp = b[i] < 0 ? (b[i] + 256) : b[i];
				int a1 = temp / 16;
				int a2 = temp % 16;
				pwdEncryption.append(seed[a1]);
				pwdEncryption.append(seed[a2]);
			}
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return pwdEncryption.toString();
	}
}
